package ATBMS.ucm;

import ATBMS.control.AdminControl;
import ATBMS.control.LoginControl;
import ATBMS.control.MainApp;
import ATBMS.control.ManagerControl;
import ATBMS.control.UserControl;
import ATBMS.modles.DAO.DAOFactory;
import ATBMS.modles.DAO.UserDAO;
import ATBMS.modles.User;
import ATBMS.view.admin.AdminViewImpl;
import ATBMS.view.manager.ManagerViewImpl;
import ATBMS.view.user.UserViewImpl;

/**
 * Delete User Use Case Implement
 */
public class UCDeleteUser implements UCController {

    private UserControl uc;
    private String userName;

    public UCDeleteUser(UserControl uc, String userName) {
        this.uc = uc;
        this.userName = userName;
    }

    public void run() {

        UserDAO userdao = DAOFactory.getUserDAO();
        if (userdao == null) {
            uc.getUserView().alert("Can't Connect To DB!");
            return;
        }
        String password=uc.getUserView().inputDialog("Please input your password");
        User user = new User(userName,password);
        if ((user = userdao.validateUser(user)) == null) {
            uc.getUserView().alert("Password Wrong!");
            return;
        }
        userdao.delete(user.getUid());
        uc.getUserView().alert("You have deleted yourself!");
        MainApp.getApplication().exit();
    }
}
